package com.clps.algorithm.chapter14.房屋偷盗;

public class 房屋偷盗_02 {

    public static void main(String[] args) {
    }

    public  int rob(int[] nums){
        if(nums.length == 0){
            return  0;
        }

        int[] dp = new int[nums.length];
        dp[0] = nums[0];

        if(nums.length >1){
            dp[1] = Math.max(nums[0],nums[1]);
        }
        for (int i = 0; i <nums.length ; i++) {
            dp[i] = Math.max(dp[i - 1], dp[i - 2] + nums[i]);
        }
        return  dp[nums.length -1];
    }
}
